package com.cli.unified_data_format.exception;

import com.cli.unified_data_format.model.ResultStatus;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/9/20 1:01
 * @Version 1.0
 **/
public class BaseException extends RuntimeException {
    private final ResultStatus error;
    private String description;
    private final HashMap<String, Object> data = new HashMap<>();

    public BaseException(ResultStatus error, String description, Map<String, Object> data) {
        super(error.getMessage());
        this.error = error;
        this.description = description;
        if (!ObjectUtils.isEmpty(data)) {
            this.data.putAll(data);
        }
    }

    protected BaseException(ResultStatus error, String description, Map<String, Object> data, Throwable cause) {
        super(error.getMessage(), cause);
        this.error = error;
        this.description = description;
        if (!ObjectUtils.isEmpty(data)) {
            this.data.putAll(data);
        }
    }

    public ResultStatus getError() {
        return error;
    }

    public Map<String, Object> getData() {
        return data;
    }

}
